#define _CRT_SECURE_NO_WARNINGS

////https://leetcode.cn/problems/recursive-mulitply-lcci/
//class Solution {
//public:
//    int multiply(int A, int B) {
//        if (B == 0) return 0;
//        if (B == 1) return A;
//        int C = 0;
//        if (B & 1 > 0) {
//            C = A;
//        }
//        return multiply(A, B >> 1) + multiply(A, B >> 1) + C;
//    }
//};
//
//
////https://leetcode.cn/problems/check-permutation-lcci/
//class Solution {
//public:
//    bool CheckPermutation(string s1, string s2) {
//        if (s1.size() != s2.size())
//            return false;
//        int count1[26] = { 0 };
//        int count2[26] = { 0 };
//        for (auto ch : s1)
//        {
//            count1[ch - 'a']++;
//        }
//        for (auto ch : s2)
//        {
//            count2[ch - 'a']++;
//        }
//        for (int i = 0; i < 26; i++)
//        {
//            if (count1[i] != count2[i])
//            {
//                return false;
//            }
//        }
//        return true;
//    }
//};


//https://leetcode.cn/problems/set-mismatch/
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* findErrorNums(int* nums, int numsSize, int* returnSize) {
    *returnSize = 2;
    int* same = (int*)malloc(sizeof(int) * numsSize);
    assert(same);
    memset(same, 0, numsSize * 4);
    for (int i = 0; i < numsSize; i++)
    {
        same[nums[i] - 1]++;
    }
    int* tmp = (int*)malloc(8);
    for (int i = 0; i < numsSize; i++)
    {
        if (same[i] == 0)
        {
            tmp[1] = i + 1;
        }
        if (same[i] == 2)
        {
            tmp[0] = i + 1;
        }
    }
    return tmp;
}